﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
    <style>
    </style>
}

<div class="layui-card">
    <div class="layui-card-body">
        <blockquote class="layui-elem-quote layui-border-red">此操作将把以下 @ViewBag.ContentNum 篇内容复制到指定栏目，确定吗？</blockquote>
        <table class="layui-table">
            <colgroup>
                <col width="80">
                <col>
                <col width="160">
                <col width="130">
            </colgroup>
            <thead>
                <tr>
                    <th>内容ID</th>
                    <th>内容标题</th>
                    <th>添加时间</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody>
                @if (ViewBag.ContentList != null)
                {
                    foreach (var item in ViewBag.ContentList)
                    {
                        <tr>
                            <td><input type="hidden" value="@item.Id">@item.Id</td>
                            <td>@item.Title</td>
                            <td>@item.CreateDate</td>
                            <td>
                                @if (item.Checked == 1)
                                {
                                    <span class="layui-badge layui-bg-orange">草稿</span>
                                }
                                else if (item.Checked == 2)
                                {
                                    <span class="layui-badge layui-bg-cyan">待审核</span>
                                }
                                else if (item.Checked == 3)
                                {
                                    <span class="layui-badge layui-bg-green">已审核</span>
                                }
                                else
                                {
                                    <span class="layui-badge">终审退稿</span>
                                }
                            </td>
                        </tr>
                    }
                }

            </tbody>
        </table>
        <form class="layui-form" lay-filter="user-form" style="padding: 15px 0 0 0;">
            <input type="hidden" id="Ids" value="@ViewBag.Ids" />
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">复制到栏目</label>
                <div class="layui-input-block">
                    <input id="channelcascader" name="TargetChannelId" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">复制后删除</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="IsDeleteAfterTranslate" value="1" title="删除">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-hide" lay-submit lay-filter="contenttrans-submit" id="contenttrans-submit">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

@section scripts{
    <script>
        layui.use(['form', 'lscom', 'layCascader'], function () {
            let form = layui.form;
            let $ = layui.jquery;
            let lscom = layui.lscom;
            var layCascader = layui.layCascader;
            let MODULE_PATH = "/Cms/Content/";
            var index = parent.layer.getFrameIndex(window.name);
            lscom.ajax({
                url: "/Cms/Channel/GetChannleCascader?channelId=0",
                type: 'GET',
                lsHandleError: false
            }).done(function (data) {
                if (data.code == 0) {
                    layCascader({
                        elem: '#channelcascader',
                        options: data.data,
                        clearable: true
                    });
                }
            }).fail(function (message) {
                lscom.notify.error(message);
            })
            window.submitForm = function () {
                $("#contenttrans-submit").click();
            }
            form.on('submit(contenttrans-submit)', function (data) {

                data.field.ContentIds = $('#Ids').val().split(',');;
                if (data.field.TargetChannelId == "") {
                    parent.layer.msg("请选择复制到栏目", {
                        icon: 3,
                        time: 1000
                    });
                }
                var field = data.field;
                var waitIndex = parent.layer.load(2);
                lscom.ajax({
                    url: "/Cms/Content/SetTranslate",
                    data: JSON.stringify(field),
                    lsHandleError: false
                }).done(function (data) {
                    if (data.code == 0) {
                        data.index = index;
                        let parentWindow = parent.selectedWindow().window;
                        parentWindow.saveCallback(data);
                    }
                }).fail(function (message) {
                    lscom.notify.error(message);
                }).always(function () {
                    parent.layer.close(waitIndex);
                });
                return false;
            });


        });
    </script>
}
